#ifndef CLIENT_H
#define CLIENT_H

#include "server.h"

#include <QObject>
#include <QHostAddress>
#include <QMutex>


class PeerManager;
class Connection;
class Message;
class RttmData;
class AccData;
class Client : public QObject
{
    Q_OBJECT
	
	
	
public:
    explicit Client();

	void start();
	void sendRttmMessage(const Message &message);
	
    void sendMessage(const QString &message);
    QString nickName() const;
    //bool hasConnection(const QHostAddress &senderIp, int senderPort = -1) const;
	
signals:
	void newRttmMessage(const Message &message);
	void newAccMessage(const Message &message);
	

    void newRttmConnection();
    void lostRttmConnection();
	void newAccConnection();
    void lostAccConnection();
	
	
private slots:
    void rttmConnection(Connection *connection);
    void accConnection(Connection *connection);	
    void connectionError(QAbstractSocket::SocketError socketError);
    void disconnected();
    void readyForUse();
	
private:
    void removeRttmConnection(Connection *connection);
    void removeAccConnection(Connection *connection);
	
	void sendRttmMessage(const Message &message, const RttmData *connection);
	
private:
    Server rttmServer;
	Server accServer;
	
	QMutex rttmOperation;
	QMutex accOperation;	
	
    QList<RttmData *> rttms;
    QList<AccData *> accs;	
};

#endif // CLIENT_H
